package com.gxa.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.common.LayR;
import com.gxa.common.R;
import com.gxa.mapper.developMapper;
import com.gxa.param.MyTableParam;
import com.gxa.pojo.Customer;
import com.gxa.pojo.Develop;
import com.gxa.service.developService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.sql.Timestamp;
import java.util.List;

@Service
public class developServiceImpl implements developService {
    @Autowired
    private developMapper mapper;

    @Override
    public LayR list(MyTableParam param) {

        PageHelper.startPage(param.getPage(),param.getLimit());

        List<Develop> develops  = mapper.findAll(param);

        PageInfo<Develop> emplPageInfo = new PageInfo<>(develops);


        return new LayR(0,"success",emplPageInfo.getList(),emplPageInfo.getTotal());

    }

    @Override
    public R add(Develop develop, HttpSession session) {
        develop.setControlerName((String) session.getAttribute("emplName"));
        develop.setCreateTime(new Timestamp(System.currentTimeMillis()));
        develop.setLastControlTime(new Timestamp(System.currentTimeMillis()));
        mapper.save(develop);

        return new R(200,"添加成功");
    }

    @Override
    public R findById(Integer id) {

        Develop develop = mapper.findByPk(id);

        return new R(200,"success",develop);
    }

    @Override
    public R edit(Develop develop) {

        mapper.update(develop);

        return new R(200,"修改成功");
    }

    @Override
    public R deleteOne(Integer id) {
        mapper.deleteOneById(id);
        return new R(200,"删除成功");
    }



    @Override
    public R deleteAll(String[] ids) {
        mapper.deleteAll(ids);
        return new R(200,"删除成功");
    }


}
